/**********************************************************
 * bike_data.h - contains code for the data structure
 * storing the bike data.
 *
 * By: Team 4
 * *******************************************************/

#ifndef BIKE_DATA_H
#define BIKE_DATA_H


/**********************************************************
 * INCLUDES
 * *******************************************************/
#include <stdbool.h>

/**********************************************************
 * Defining data structures
 * *******************************************************/

typedef struct bdata * BikeDataPtr;

typedef struct bdata{
	// variables for synchronization
	
	// Data from sensors
	float Speed;
	float Cadence;
	int HeartRate;
  float Calories;

	// Data from sensors averages
	float avgSpeed;
	float avgCadence;
	float avgHeartRate;

	// Data from sensors maximums
	float maxSpeed;
	float maxCadence;
	float maxHeartRate;

	// Data from sensors minimum
	float minSpeed;
	float minCadence;
	float minHeartRate;

	// From Data Structure
	int WheelRevolutionCount;

  // Time variables
	int ElapsedTimeHour;
	int ElapsedTimeMin;
	long int ElapsedTimeMilSec;

	// Set at start
	int Age;
	int Weight;
	bool Gender; //true = Male, false = Female

} BikeData;

// Used in the Gender section of the Data Structure
#define MALE true
#define FEMALE false

/**********************************************************
 * Initialize - Function to create a BikeData and set all
 * parts to zero and initalize mutex.
 * *******************************************************/

void initializeBikeData(BikeDataPtr data);

/**********************************************************
 * Update Functions - Functions to update the derived parts
 * of the data in the structure from the other parts
 * *******************************************************/

void update(BikeDataPtr data, float newSpeed, float newCadence, int newHeartRate, int updateWheelCount, int elapsedTime);

void resetCalories(BikeDataPtr data);
void resetWheelRevolutionCount(BikeDataPtr data);

void incrementWheelRevolutionCount(BikeDataPtr data, int update);

void resetElapsedTime(BikeDataPtr data);
void incrementElapsedTimeBy(BikeDataPtr data, int milSec);

void setPersonalData(BikeDataPtr data,int age,int weight, bool gender);
 

/**********************************************************
 * Accessor Functions - Need to access the data structure
 * through accessor functions to ensure synchronization
 * *******************************************************/
float getSpeed(BikeDataPtr data);
float getCadence(BikeDataPtr data);
int getHeartRate(BikeDataPtr data);
float getCalories(BikeDataPtr data);

float getAvgSpeed(BikeDataPtr data);
float getAvgCadence(BikeDataPtr data);
int getAvgHeartRate(BikeDataPtr data);

float getMaxSpeed(BikeDataPtr data);
float getMaxCadence(BikeDataPtr data);
int getMaxHeartRate(BikeDataPtr data);

float getMinSpeed(BikeDataPtr data);
float getMinCadence(BikeDataPtr data);
int getMinHeartRate(BikeDataPtr data);

int getWheelRevolutionCount(BikeDataPtr data);

float getElapsedTime(BikeDataPtr data);
long int getElapsedTimeMilSec(BikeDataPtr data);
int getElapsedTimeMin(BikeDataPtr data);
int getElapsedTimeHour(BikeDataPtr data);

int getAge(BikeDataPtr data);
int getWeight(BikeDataPtr data);
bool getGender(BikeDataPtr data);

/**********************************************************
 * Conversion Functions - converts data stored in the 
 * data structure to new forms.
 * *******************************************************/

// HeartRateZone - converst HeartRateBeatsPerSecond to a zond

float HeartRatePercent(float HeartRateBeatsPerMin, float age);

// DistanceTraveledMiles - conversts WheelRevolutionCount

float DistanceTraveledMiles(float WheelRevolutionCount);

#endif //BIKE_DATA_H
